package com.example.Handler;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.examplee.username.httpfrist_01.R;

public class HandlerzixiancActivity extends AppCompatActivity {
Handler handler=new Handler(){

    @Override
    public void handleMessage(Message msg) {

        Message message=handler.obtainMessage();
        System.out.println("main");
        handler.sendMessageDelayed(message,1000);
    }
};
    Handler mHandler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_handlerzixianc);
        HandlerThread handlerThread=new HandlerThread("handlerThread");
        handlerThread.start();
        mHandler=new Handler(handlerThread.getLooper()){

            @Override
            public void handleMessage(Message msg) {

                Message message=mHandler.obtainMessage();
                System.out.println("thread");
               handler.sendMessageDelayed(message,1000);
            }
        };

    }
    public void btn(View v){
        switch (v.getId()){
            case R.id.send:
                handler.sendEmptyMessage(1);
                break;
            case R.id.stop:
                handler.removeMessages(1);
                break;
        }
    }
}
